// areaLeader/pages/withdrawalRecord/withdrawalRecord.js
var common = require("../../../common/common.js").common;

var app = getApp();

Page({
    /**
   * 页面的初始数据
   */
    data: {
        chooseClass: 0,
        page: 1,
        search_on: "",
        details: []
    },
    /**
   * 生命周期函数--监听页面加载
   */
    onLoad: function(options) {
        wx.hideShareMenu();
        let that = this;
        this.setData({
            domain: app.globalData.domain.slice(0, -10)
        });
        if (options.id) {
            that.setData({
                level_id: options.id
            });
        }
        that.drawRecord();
    },
    /**
   * 生命周期函数--监听页面初次渲染完成
   */
    onReady: function() {},
    /**
   * 生命周期函数--监听页面显示
   */
    onShow: function() {},
    /**
   * 生命周期函数--监听页面隐藏
   */
    onHide: function() {},
    /**
   * 生命周期函数--监听页面卸载
   */
    onUnload: function() {},
    /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
    onPullDownRefresh: function() {
        let that = this;
        that.setData({
            details: [],
            page: 1
        });
        that.drawRecord();
        wx.stopPullDownRefresh();
    },
    /**
   * 页面上拉触底事件的处理函数
   */
    onReachBottom: function() {
        let that = this;
        that.drawRecord();
    },
    /**
   * 用户点击右上角分享
   */
    onShareAppMessage: function() {},
    drawRecord: function(e) {
        let that = this;
        common.request({
            endpoint: "Level/level_user/draw_record",
            method: "post",
            data: {
                page: that.data.page,
                status: that.data.chooseClass,
                level_id: that.data.level_id
            },
            success: res => {
                var details = res.extra;
                if (details.length > 0) {
                    details = that.data.page == 1 ? details : that.data.details.concat(details);
                    that.setData({
                        details: details,
                        page: that.data.page + 1
                    });
                }
            }
        });
    },
    chooseClass: function(e) {
        let that = this;
        that.setData({
            chooseClass: e.currentTarget.dataset.type,
            details: [],
            page: 1
        });
        that.drawRecord();
    }
});